package com.qs.redis.redisson;

import org.redisson.Redisson;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.Map;
import java.util.Set;

/**
 * 使用redisson连接redis-cluster集群
 *
 * @author qinyupeng
 * @since 2019-12-13 14:57:01
 */
public class RedissonClientDemo {

    public static void main(String[] args) {
        Config config = new Config();
        config.useClusterServers()
                .addNodeAddress("redis://172.16.109.130:7000")
                .setTimeout(10000)
                .setConnectTimeout(10000)
                .setRetryAttempts(3);

        RedissonClient redissonClient = Redisson.create(config);
        redissonClient.getBucket("name").set("张三");
        System.out.println(redissonClient.getBucket("name").get());

        RMap<Object, Object> map = redissonClient.getMap("user");
        map.put("name", "张三");
        map.put("age", 20);

        Set<Map.Entry<Object, Object>> entrySet = redissonClient.getMap("user").entrySet();
        for (Map.Entry<Object, Object> entry : entrySet) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            System.out.println("key=" + key + ", value=" + value);
        }

        redissonClient.shutdown();
    }
}
